import request from "@/api/request";

// get server information
export function getServerInfo() {
  return request({
    url: '/service/server/info',
    method: 'get',
    data: {}
  });
}

export function getMenuList() {
  return request({
    url: '/service/server/menu_list',
    method: 'get',
    data: {}
  });
}

// get article list
export function getDataList(pageInfo) {
  return request({
    url: '/service/data/list',
    method: 'post',
    data: {
      ...pageInfo,
      list: []
    }
  });
}

// get login verify code
export function getVerifyCode() {
  return request({
    url: '/service/user/verify_code',
    method: 'get',
    data: {}
  })
}

export function createQRCode(param) {
  return request({
    url: '/service/resource/qr_code_gen',
    method: 'post',
    data: {
      ...param
    }
  })
}

// get email verify code when register
export function getEmailCode(email, operation) {
  return request({
    url: '/service/user/email_code',
    method: 'post',
    data: {
      email: email,
      operation: operation
    }
  })
}

// do register and get token
export function register(userInfo) {
  return request({
    url: '/service/user/register',
    method: 'post',
    data: {
      ...userInfo
    }
  })
}

// 登录获取token
export function login(userInfo) {
  return request({
    url: '/service/user/login',
    method: 'post',
    data: {
      ...userInfo,
    }
  })
}

//logout
export function logout(token) {
  return request({
    url: '/service/user/logout',
    method: 'delete',
    data: {
      token: token
    }
  })
}

// check email exist
export function checkEmail(email) {
  return request({
    url: '/service/user/check_email',
    method: 'post',
    data: {
      email: email
    }
  })
}

// reset password when forget
export function forget(userInfo) {
  return request({
    url: '/service/user/forget',
    method: 'post',
    data: {
      ...userInfo
    }
  })
}

// get user information
export function getUserInfo() {
  return request({
    url: '/service/info/detail',
    method: 'post',
    data: {
      token: ''
    }
  })
}

// get email verify code after login
export function getEmailCodeByToken() {
  return request({
    url: '/mail/update/code',
    method: 'get',
    data: {
      'token': ''
    }
  })
}

// update (login/delete character) password
export function updatePwd(userInfo) {
  return request({
    url: '/user/update/account',
    method: 'post',
    data: {
      'formData': {
        ...userInfo
      },
      'option': 'pass',
      'token': ''
    }
  })
}

// check email by code
export function checkEmail1(code) {
  return request({
    url: '/user/verify/emailCode',
    method: 'post',
    data: {
      'code': code,
      'token': ''
    }
  })
}

// get verify code by email when update bind email
export function getEmailCodeByEmail(email) {
  return request({
    url: '/mail/update/email/code?email=' + email,
    method: 'get',
    data: {
      'token': ''
    }
  })
}

// update bind email
export function updateBindEmail(emailInfo) {
  return request({
    url: '/user/update/email',
    method: 'post',
    data: {
      'newEmail': emailInfo.newEmail + '@qq.com',
      'newCode': emailInfo.newCode,
      'token': ''
    }
  })
}

// get recharge player list
export function getPlayerList(pageInfo) {
  return request({
    url: '/player/recharge',
    method: 'get',
    data: {
      ...pageInfo
    }
  })
}
